using Cysharp.Threading.Tasks;
using IQIGame.Onigao.Framework;
using IQIGame.Onigao.Game;

namespace IQIGame.Onigao.GamePlay
{
    public class ProcedureLogin : ProcedureBase
    {
        public override void OnEnter()
        {
            switch (ProcedureGame.enterMode)
            {
                case EnterGameType.Login:
                    if (ManagerCenter.ProjectSetting.IsSDKMode())
                    {
                        SDKLogin().Forget();
                    }
                    else
                    {
                        BuiltinLogin();
                    }
                    break;
                default:
                    ChangeState<ProcedureGame>();
                    break;
            }
        }

        async UniTaskVoid SDKLogin()
        {
            await ManagerCenter.UI.ShowWindowAsync<UILogin>();
            SDKModule.Instance.StartLogin();
        }

        void BuiltinLogin()
        {
            ManagerCenter.UI.ShowWindow<UILogin>();
        }

        public override void OnLeave()
        {
            ManagerCenter.UI.CloseWindow<UILogin>();
            ManagerCenter.UI.CloseWindow<UIRoleCreate>();
        }

        public override void OnUpdate(float deltaTime, float unscaledDeltaTime)
        {

        }
    }
}
